﻿<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="PlaceOnLiveMap.ascx.cs"
    Inherits="GNSWebSite.Controls.PlaceOnLiveMap" %>
<div>
    <script type="text/javascript" language="javascript">

    var theMap = null; 
    var locations = null;
    var pixel = null;
    var clickEvent = null;
    var LL = null;

   
     $(document).ready(function(){
        theMap = new VEMap('map');
        theMap.LoadMap(new VELatLong(47.6, -122.33), 10, 'h', false);
        theMap.AttachEvent("onclick", PixelClick);
        
        $("#<%= btnPlaceAddress.ClientID %>").click(function() {
              theMap.Find(null, $("#txtAddress").val());              
    });
        //theMap.LoadMap();
        //theMap.HideDashboard();
        //zoomTo(53.3862, -1.4345, 14);
    });
    
     function PixelClick(e)
     {
   	        var x = e.mapX;
            var y = e.mapY;
            pixel = new VEPixel(x, y);
            LL = theMap.PixelToLatLong(pixel);
            theMap.DeleteAllPushpins();
            var pin = new VEPushpin(1, LL, null, 'Your location here', 'Save or change location');
            theMap.AddPushpin(pin);
            //map.FindLocations(LL, GetResults);
            $("#<%= hfLatitude.ClientID %>").val(LL.Latitude);
            $("#<%= hfLontitude.ClientID %>").val(LL.Longitude);
     }
     
     function GetResults(locations)
         {
      	    var s="Results for " + LL.Latitude + ", " + LL.Longitude + ": ";
            if(locations != null)
            {
	             s+=locations[0].Name;
               
            }
            else
            {
               s+="No Result found.";
            } 

            alert(s);
         }

//    function resizeMap(w, h) {
//        theMap.Resize(w, h);
//    }

//    function panMap(dx, dy) {
//        theMap.Pan(dx, dy);
//        window.external.onContentChange();
//    }

//    function centerAndZoom(lat, lon, zoomDelta) {
//        theMap.SetCenterAndZoom(new VELatLong(lat, lon), theMap.GetZoomLevel() + zoomDelta);
//        window.external.onContentChange();
//    }

//    function zoomTo(lat, lon, zoomLevel) {
//        theMap.SetCenterAndZoom(new VELatLong(lat, lon), zoomLevel);
//    }

//    function _onMapError(e) {
//        window.external.onError();
//    }

//    function pixelToLatLon(x, y) {
//        m = theMap.PixelToLatLong(new VEPixel(x, y));
//        return m.Latitude + ',' + m.Longitude;
//    }

//    function latLonToPixel(lat, lon) {
//        m = theMap.LatLongToPixel(new MapLocation(new VELatLong(lat, lon)));
//        return m.X + ',' + m.Y;
//    }
    </script>

    <div>
        <input type="text" id="txtAddress" />
        <asp:Button ID="btnPlaceAddress" OnClientClick="return false;" runat="server" meta:resourcekey="btnPlaceAddress" />
        <asp:HiddenField ID="hfLatitude" runat="server" />
        <asp:HiddenField ID="hfLontitude" runat="server" />
        <div style=" position:relative; width: 400px; height: 400px;" id="map">
        </div>
    </div>
</div>
